classdef BaseClass < handle
    properties (Constant)
        BRACKET_PATTERN = '(?<=^\s*)\(.*?\)' % Pattern for matching a pair of round brackets with input arguments.
    end
    
    
    
    
    methods (Static)
        function [cond, remC, remSh, remLe] = separateCondition(key, c, sh, le)
            import preparser.control.Keyword;
            BR = sprintf('\n');
            ix = ( c==';' | c==BR ) & le==1;
            pos = find(ix,1);
            % Input string c contains the initial keyword, key.
            if isempty(pos) || any(sh(len(key)+1:pos-1)~=Keyword.NONE)
                % Throw error if end of control condition is not found or control condition
                % includes another control keyword.
                throwCode( exception.Preparser.CTRL_UNFINISHED_CONDITION, ...
                    c);
            end
            cond = c(len(key)+1:pos-1);
            % Include the line break but not the semicolon in the remainder.
            if c(pos)==';'
                posRem = pos+1;
            else
                posRem = pos;
            end
            remC = c(posRem:end);
            remSh = sh(posRem:end);
            remLe = le(posRem:end);
        end
        
        
        
        
        function [arg, c, sh] = getBracketArg(key, c, sh)
            import preparser.control.*;
            c = c(len(key)+1:end);
            sh = sh(len(key)+1:end);
            [arg, to] = regexp(c,BaseClass.BRACKET_PATTERN, 'once', 'match', 'end');
            arg = strtrim(arg(2:end-1));
            c = c(to+1:end);
            sh = sh(to+1:end);
        end
    end
    
    
    
    
    methods (Abstract)
        varargout = writeFinal(varargin)
    end
end
